package com.example.demo.MyBatis.service;

import com.example.demo.MyBatis.dao.UserDao;
import com.example.demo.MyBatis.entity.User;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author : 叶荻风
 * @create : 2024/5/27 11:41
 */
public class UserServiceImpl implements UserService{
    private UserDao userDao;

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    @Override
    @Transactional
    public void register(User user) {
        userDao.save(user);
        throw new RuntimeException("测试后");
    }

    public static void main(String[] args) {
        User user = new User();
        user.setName("A");
        user.setPassword("B");
        ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext(
                "applicationContext.xml");
        UserService userService = classPathXmlApplicationContext.getBean("userService", UserService.class);
      userService.register(user);
    }
}
